package com.sunni.controller;

import com.sunni.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/get")
public class getMethod {

    @RequestMapping(value = "/olg",params = {"name","id"}) //,method = RequestMethod.POST
    public String getOlg(@RequestParam("name") String name01, Integer id){
                        // http://localhost/get/olg?name=wuwukai&age=5   (起别名，前台传入叫xxx, 后台改成xxx)
//                                                                  age前台是String类型传来，后台SpringMVC自动转成Integer。SpringMVC自带数据类型转化的功能。
        System.out.println(name01);
        System.out.println(id);
        System.out.println("执行了Olg…………");
        return "奥利给" ;
    }

//    RESFUL风格传参
    @RequestMapping("/index/{name}/{id}")
    public String getIndex(@PathVariable("name") String name,@PathVariable("id") Integer id){
        System.out.println(name);
        System.out.println(id);
        return "index";
    }



    /*
    * 2021.04.05 */

// 01.   获取Cookie值
    @RequestMapping(value = "/cookie")
    public String getCookie(@CookieValue(value = "JSESSIONID") String sessionId){
        System.out.println(sessionId);
        return "index";
    }

// 02.   SpringMVC自动接收 对象
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public String save(User user){ //自定义类的赋值，，通过set方法赋值。
        System.out.println(user);
        return "index";
    }

// 03.   SpringMVC 转发 & 重定向
    @RequestMapping(value = "/forward") // 转发，地址栏不变
    public String forward(){
        return "forward:/index.jsp";
}
    @RequestMapping(value = "/redirect") // 重定向，地址栏改变
    public String redirect(){
        return "redirect:/index.jsp";
    }

// 04.  返回集 对象,,,,,,,把 对象 当做结果返回，会展示在网页上。
    @RequestMapping(value = "/packageType")
    @ResponseBody
    public String getPackageType(@RequestParam(value = "num",required = false,defaultValue = "1111") Integer id){
        return id+"";
    }
}
